package com.yryp.sign.mq;

import com.yryp.sign.mq.utils.MqrsaUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class Sender {


    @Autowired
    private RabbitTemplate template;

    /**
     *
     * @param jsonMsg 需要发送的信息
     * @throws Exception RSA加密错误
     */
    public void send(String jsonMsg) throws Exception {

//         加密
        String encryptRSA  = MqrsaUtil.encryptRSA(jsonMsg);
        Message message = MessageBuilder
                .withBody(encryptRSA.getBytes())
                .setContentType(MessageProperties.CONTENT_TYPE_BYTES)
                .setContentEncoding("utf-8")
                .build();
        template.convertAndSend(
                "dc_hkws_memberInfo_exchange",
                "dc_hkws_memberInfo_routingkey",
                message);
    }
}
